﻿using System;
using System.Windows.Forms;
using ExcelTools;
using Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;

namespace ExcelToolsSampleDocument
{
  public partial class ThisWorkbook
  {
    private void ThisWorkbook_Startup(object sender, EventArgs e)
    {
      ExcelApplication.BindTo(Globals.ThisWorkbook.ThisApplication);
      SamplesActionPane pane = new SamplesActionPane();
      ActionsPane.Controls.Add(pane);
      pane.Dock = DockStyle.Fill;
      FillCells(new string[] {"one", "two", "three", "four"});
    }

    private void ThisWorkbook_Shutdown(object sender, EventArgs e)
    {
    }

    #region VSTO Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InternalStartup()
    {
      Startup += new EventHandler(ThisWorkbook_Startup);
      Shutdown += new EventHandler(ThisWorkbook_Shutdown);
    }

    #endregion

    private void FillCells(string[] strings)
    {
      int rowCount = 1;
      foreach (string stringValue in strings)
      {
        Range range = ThisApplication.Cells[rowCount++, 1] as Range;
        //range.set_Value(XlRangeValueDataType.xlRangeValueDefault, stringValue);
        range.Value = stringValue;
      }

      Worksheet ws = this.ActiveSheet as Worksheet;
      rowCount = 1;
      foreach (string stringValue in strings)
      {
        Range range = ws.Cells[rowCount++, 2] as Range;
        range.set_Value(XlRangeValueDataType.xlRangeValueDefault, stringValue);
      }
    }
  }
}